//
//  UIView+Action.m
//  EHome
//
//  Created by Apple on 16/3/3.
//  Copyright © 2016年 enjoy. All rights reserved.
//

#import "UIView+Action.h"

@implementation UIView (Action)
- (UIViewController*)viewController {
   // 通过UIView对象获取所属的UIViewController
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}


- (UINavigationController *)getCurrentNavigationController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            return (UINavigationController *)nextResponder;
        }
    }
    return nil;
}
@end
